﻿#pragma execution_character_set("utf-8")
#include <QFileDialog>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog>
#include <QToolBar> //工具栏
#include <QStatusBar>
#include <QDockWidget>
#include <QProgressBar>
#include "dialognet.h"
#include <QString>


#define IO_SOCKET
void MainWindow::initSocketCfg(void){
    settings_ = new QSettings(QApplication::applicationDirPath() + "/NetworkConfig.ini", QSettings::IniFormat);
    settings_->setIniCodec("UTF8");
    file_path_ = settings_->value("src_path").toString();
    ip_addr = (settings_->value("ip_addr").toString());
    if(settings_->value("send_interval").isValid())
        send_interval = settings_->value("send_interval").toInt();
    if(settings_->value("port").isValid())
        port = settings_->value("port").toInt();
    if(settings_->value("start_frame").isValid())
        start_frame = settings_->value("start_frame").toInt();
    if(settings_->value("replay_cnt").isValid())
        replay_cnt = settings_->value("replay_cnt").toInt();

    file_path_ = settings_->value("src_path").toString();
    QDir dir(file_path_);
    file_list_ = dir.entryList(QDir::Files,QDir::Name);



#if 0
    //创建通讯类
    async_process_ = new AsyncProcess();
    thread_ = new QThread(this);
    async_process_->moveToThread(thread_);
    //启动线程
    thread_->start();

#endif
    connect(&_TcpSendTimer, &QTimer::timeout, this, &MainWindow::startSendData);
    //接收到连接信号时，启动websocket 运行主线程
    connect(this, &MainWindow::sg_socket_connect, this, &MainWindow::asyncConnect);

    //点击连接按钮时，发送启动socket信号 sg_socket_connect
    connect(btn_socket_connect, &QPushButton::clicked,[&](){
        ip_addr = (settings_->value("ip_addr").toString());
        if(settings_->value("port").isValid())
            port = settings_->value("port").toInt();
       // async_process_->host = ip_addr.toStdString();
      //  async_process_->port = QString::number(port).toStdString();
        emit sg_socket_connect();
        qDebug() << send_interval;

    });

}


#if 0
    QString file_path = file_path_ + "/" + file_list_[file_index_];
    ui->textBrowser->append(file_list_[file_index_]);
   // async_process_->sendData(file_path);
    
    cv::Mat img;
   // async_process_->getRecvData(img);
    img = img / 64;
    cv::Mat tt;
    std::vector<cv::Mat> oimg;
    cv::Mat _img;
    img.convertTo(tt, CV_8UC3);
    oimg.push_back(tt);
    oimg.push_back(tt.clone());
    oimg.push_back(tt.clone());
    cv::merge(oimg, _img);
    emit outDisplay(
        QPixmap::fromImage(
            QImage(
                _img.data,
                _img.cols,
                _img.rows,
                _img.step,
                QImage::Format_RGB888)
            .rgbSwapped()));
#endif

